<?php

require_once 'PipesImpl/FileSystem/Directory.php';
require_once 'Pipes/Exception.php';
require_once 'Pipes/Generator/Start/Config.php';
require_once 'Pipes/Generator/Start/Index.php';

class Pipes_Generator_Start
{
    private $_root = '';
    private $_paths = array(
        'Controllers', 'Models', 'Models/Mappers', 'Models/Metas',
        'Models/Savers', 'PageTypes', 'Public', 'Savers', 'Views'
    );

    private $_options = array(
        'disable_database' => false,
    );

    public function __construct(PipesImpl_FileSystem_Directory $root, array $options = array())
    {
        if (!$root->exists()) {
            throw new Pipes_Exception(get_class($root) . ' does not represent a valid directory');
        }
        $this->_root = $root->toString();
        $this->_options = array_merge($this->_options, $options);
    }
    
    public function start($path)
    {
        $projectPath = new Pipes_FileSystem_Directory($this->_root . DIRECTORY_SEPARATOR . $path);
        
        mkdir($projectPath->toString());
        foreach ($this->_paths as $pathToCreate) {
            mkdir($projectPath->toString() . DIRECTORY_SEPARATOR . $pathToCreate);
        }

        $configStarter = new Pipes_Generator_Start_Config($projectPath);
        $configStarter->create($this->_options);

        $indexStarter = new Pipes_Generator_Start_Index($projectPath);
        $indexStarter->create();
    }
}
